<template>
    <div class="login-wrap">
        <div class="bgView">

        </div>
        <div class="ms-login">
            <div class="ms-title">
                <img src="@/assets/logo(1).png" class="logo" />
                <div class="title">多店铺选择</div>
            </div>
            <ul>
                <li v-for="(item,index) in storeList" :key="index" @click="toSelectStore(item.is_choose,item.user_id)">
                    <img :src="item.logo.path" alt="">
                    <div class="info">
                        {{item.title}}
                        <i class="el-icon-arrow-right"></i>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
    export default {
        data: function() {
            return {
                storeList: []
            };
        },
        mounted() {
            this.getStoreList();
        },
        methods: {
            getStoreList() {
                this.$http.post("/api/admin/base/UserPartner").then(res => {
                    console.log(res, "多店列表");
                    if (res.code == 1) {
                        this.storeList = res.data ? res.data : [];
                    }
                });
            },
            // 选择店铺
            toSelectStore(is_choose, userId) {
                if (is_choose == 1) {
                    localStorage.removeItem('count')
                    this.$router.replace('/manaindex')
                } else {
                    let user_id = localStorage.getItem('user_id')
                    let params = {
                        user_id,
                        change_user_id: userId
                    }
                    this.$http.post('/api/admin/base/changeUserPartner', params).then(res => {
                        console.log(res, '更换结果');
                        if (res.code == 1) {
                            let token = res.data.token.access_token
                            let user_id = JSON.stringify(res.data.user_id)
                            let sid = JSON.stringify(res.data.sid)
                            let role = JSON.stringify(res.data.role)
                            let info = JSON.stringify(res.data.info)
                            let sale_type = res.data.sale_type
                            let market_id = res.data.market_id
                            localStorage.setItem('liankun_user', token);
                            localStorage.setItem('user_id', user_id);
                            localStorage.setItem('info', info);
                            localStorage.setItem('sid', sid);
                            localStorage.setItem('role', role);
                            localStorage.setItem('sale_type', sale_type)
                            localStorage.setItem('market_id',market_id)
							localStorage.setItem('packAuth',res.data.is_pk_auth)
                            localStorage.removeItem('count')
                            this.$router.replace('/manaindex')
                        }
                    })
                }
            }
        }
    };
</script>

<style scoped lang='less'>
    .login-wrap {
        position: relative;
        width: 100%;
        height: 100%;
        background-image: url(../../assets/bg.jpg);
        background-repeat: no-repeat;
        background-size: 100% 100%;

        .bgView {
            position: absolute;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, .6);
        }
    }

    .ms-title {
        width: 100%;
        line-height: 50px;
        /* text-align: center; */
        font-size: 20px;
        color: #fff;
        border-bottom: 1px solid #ddd;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 30px;

        .logo {
            width: 234px;
            height: 70px;
        }

        .title {
            color: #fff;
            font-weight: 600;
            font-size: 16px;
        }
    }

    .ms-login {
        position: absolute;
        left: 50%;
        top: 50%;
        //   right: 0;
        //   bottom: 0;
        width: 450px;
        max-height: 630px;
        //   margin: auto;
        transform: translate(-50%, -50%);
        //   margin: -190px 0 0 -175px;
        border-radius: 5px;
        background: rgba(255, 255, 255, 0.1);

        //   overflow: hidden;
        ul {
            max-height: 479px;
            overflow: auto;

            li {
                display: flex;
                align-items: center;
                padding: 20px 30px;

                img {
                    flex-shrink: 0;
                    margin-right: 10px;
                    width: 50px;
                    height: 50px;
                    border-radius: 50%;
                }

                .info {
                    width: 100%;
                    color: #ddd;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    font: 500 16px/50px PingFang SC;
                }
            }
        }

        ul::-webkit-scrollbar {
            width: 0px !important;
        }

        ul::-webkit-scrollbar {
            width: 0px !important;
            height: 0;
        }
    }

    .ms-content {
        padding: 30px 45px;
    }

    .login-btn {
        text-align: center;
    }

    .login-btn button {
        width: 100%;
        height: 36px;
        margin-bottom: 10px;
    }
</style>